% ************************************************************************ 
%     Module name   : Lynx Simulation - Track Mode Run                                                     
%                                                                          
%     Description   : This will run the Track mode on a specific target.                                                    
%                                                                          
%     $Header: /Lynx/SimulationFramework/RSP/IFS/IFSRun.m 2     15/10/08 16:08 Lwabeke $ 
%                                                                          
%    $Author: Lwabeke $	            
%                                                                         
%    $Revision: 2 $                
%                                                                         
% ************************************************************************
%     $History: IFSRun.m $ 
% 
%
% ************************************************************************
function [radarSetup] = setup_select(time, radarState, tgtCntr, param)

if (tgtCntr == 0)
    % Non-target specific, i.e. search setup to be chosen

    radarSetup.mode = 'Search';
    
    %% Step search sector
    radarState.searchSetup.sector = radarState.searchSetup.nextSector;
    
    %% Determine state and waveform for sector

    radarSetup.sector = radarState.searchSetup.sector;
    
    old_state_estimate = state_estimate_search(time, radarState);
    
    chosen_action = radarState.setup_select.Search.policy(old_state_estimate);     % Use the policy to choose the action
    
    if (rand(1) < radarState.setup_select.Search.currentExplore)
      chosen_action = ceil(rand(1)*param.learn.search.num_actions + 1e-16);
    end
    
    radarSetup.old_state_estimate = old_state_estimate;
    radarSetup.chosen_action = chosen_action;

    switch (mod(chosen_action,3)+1)
        case 1
                    radarSetup.subMode = 'NCI';
                    radarSetup.usedTime = param.radarModes.searchMode.NCI.usedTime;
        case 2
                    radarSetup.subMode = 'MTI';
                    radarSetup.usedTime = param.radarModes.searchMode.MTI.usedTime;
        case 3
                    radarSetup.subMode = 'Stationary';
                    radarSetup.usedTime = param.radarModes.searchMode.Stationary.usedTime;
    end
    
   radarSetup.nextSector = floor((chosen_action-1)/3) + 1;

else
    
    radarSetup.mode = 'Track';
    radarSetup.usedTime = param.radarModes.trackMode.usedTime;
end

